import ViewBase from "./ViewBase";
import LevelProgress from "../LevelProgress";
import Common from "../common/Common";
import Define from "../common/Define";
import UIManager from "../manager/UIManager";
import GameManager from "../manager/GameManager";
import UserInfo from "../UserInfo";
import ParticleEffectManager from "../manager/ParticleEffectManager";
import WXHelper from "../common/WXHelper";

// Learn TypeScript:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class GameWinViewCtr extends ViewBase {

    @property(cc.Node)
    nodeCenter: LevelProgress = null;

    @property(cc.Label)
    textFinishProgress: cc.Label = null;

    @property(cc.Node)
    nodeBg: cc.Node = null;

    @property(cc.Node)
    nodeClickContinue: cc.Node = null;


    refreshView(isFristRefresh:boolean = false){
 
        this.textFinishProgress.string = "恭喜第"+Common.curLevel.toString()+"关已完成";  
        UserInfo.saveGoldData();
        WXHelper.instance.submitScore();
        this.textFinishProgress.node.stopAllActions();
        Common.actionTinkColor(this.textFinishProgress.node,null,10000,0.3);
        Common.lastShowScore = Common.totalShowScore

        UserInfo.saveTotalScore();
        
        this.nodeClickContinue.stopAllActions()
        Common.actionBigSmall(this.nodeClickContinue,0.9,1);
    }

    //点击点击事件 //只调用一次
    addEvent(){
        Common.addClickEvent(this.nodeBg,this.onClick.bind(this),false);
    }

    onClick(tag:string){
        UIManager.getInstance().hideView(Define.viewUpgrade)
        UIManager.getInstance().hideView(Define.viewGameWin);
        UIManager.getInstance().showView(Define.viewBattle);

        Common.isPlaying = true;
        GameManager.instance.restartGame();
    }
       //只调用一次
    initView(){
        this.showActionType = Define.left;
    }
    //动作
    showActionCallBack(){
        UIManager.getInstance().showView(Define.viewUpgrade);
        ParticleEffectManager.getInstance().showParticleEffect(1,new cc.Vec2(320,1000),5,null,this.node);
    }
}
